*Generate Tables
global restrict_No_DustBowl "inlist(year,1950,1960,1970,1980)==1 & inlist(bpl, 5, 8, 19, 20, 22, 27, 29, 30, 31, 35, 38, 40, 46, 48, 56)==0"
global restrict_No_South "inlist(year,1950,1960,1970,1980)==1 & inlist(bplregion9, 31,32,33)==0"
global restrict_Aged27_36 "inlist(year,1950,1960)==1 & age>=27 & age<=36"

global birth inrange(birthyr,1920,1931)
global goiter goiterldscale 
global region bplregion9

global controls i.year#i.birthyr c.female c.black c.during#c.female1920bpl c.during#c.black1920bpl c.after#c.female1920bpl c.after#c.black1920bpl c.latitude#c.after c.latitude#c.during  c.pre#c.female1920bpl c.pre#c.black1920bpl c.latitude#c.pre  
	/*pre variables will drop out of most main regressions*/
	
use  "replicationdata", clear

fvset base 1920 birthyr
fvset base 1990 year
fvset base 1 bpl statefip 
fvset base 11 region 


cap erase "sumstats.csv"	
cap erase "tables_main.csv"	
cap erase "tables_online.csv"		
estimates clear
	
*Summary statistics table 

	eststo: estpost tabstat employed labforce if $birth & inrange(year,1950,1980) & $goiter<.  [weight=perwt], statistics(mean sd) columns(statistics)
	esttab est1 using sumstats.csv, title("person weight") main(mean) aux(sd) nostar unstack nonote label append

	eststo: estpost tabstat worked_40 inctot   if $birth & inrange(year,1950,1980) & $goiter<.  [weight=slwt], statistics(mean sd) columns(statistics)
	esttab est2 using sumstats.csv, title("sample line weight")  main(mean) aux(sd) nostar unstack nonote label append

	eststo: estpost tabstat schooling evermarr  schooling_sp inctot_sp ftotinc if $birth & inlist(year,1970,1980)==1 & $goiter<.  [weight=perwt], statistics(mean sd) columns(statistics)
	esttab est3 using sumstats.csv, title("person weight")  main(mean) aux(sd) nostar unstack nonote label append
		/*can use perwt for schooling b/c only for 78 here*/
	eststo: estpost tabstat agemarr   if $birth & inlist(year,1970,1980)==1 & $goiter<.  [weight=weightagemarr], statistics(mean sd) columns(statistics)
	esttab est4 using sumstats.csv, title("person weight")  main(mean) aux(sd) nostar unstack nonote label append
		/*because of the divide by 2*/		
	estimates clear 

	forvalues i=0/1 {
		eststo: estpost tabstat employed labforce if $birth & inrange(year,1950,1980) & $goiter<. & male==`i'  [weight=perwt], statistics(mean sd) columns(statistics)
		esttab est1 using sumstats.csv, title("person weight & male==`i' ") main(mean) aux(sd) nostar unstack nonote label append
		
		eststo: estpost tabstat worked_40 inctot   if $birth & inrange(year,1950,1980) & $goiter<. & male==`i'   [weight=slwt], statistics(mean sd) columns(statistics)
		esttab est2 using sumstats.csv, title("sample line weight & male==`i' ")  main(mean) aux(sd) nostar unstack nonote label append
		
		eststo: estpost tabstat schooling evermarr  schooling_sp inctot_sp ftotinc if $birth & inlist(year,1970,1980)==1 & $goiter<. & male==`i'  [weight=perwt], statistics(mean sd) columns(statistics)
		esttab est3 using sumstats.csv, title("person weight & male==`i'")  main(mean) aux(sd) nostar unstack nonote label append
			/*can use perwt for schooling b/c only for 78 here*/			
		eststo: estpost tabstat agemarr   if $birth & inlist(year,1970,1980)==1 & $goiter<. & male==`i' [weight=weightagemarr], statistics(mean sd) columns(statistics)
		esttab est4 using sumstats.csv, title("person weight & male==`i'")  main(mean) aux(sd) nostar unstack nonote label append
			/*because of the divide by 2*/
		estimates clear
	}

*Summary statistics by year
	forvalues y=1950(10)1980 {
		eststo: estpost tabstat employed labforce if $birth & year==`y' & $goiter<. [weight=perwt], statistics(mean sd) columns(statistics)
		esttab est1 using sumstats.csv, title("year `y' person weight") main(mean) aux(sd) nostar unstack nonote label append
		
		eststo: estpost tabstat worked_40 inctot   if $birth & year==`y' & $goiter<.  [weight=slwt], statistics(mean sd) columns(statistics)
		esttab est2 using sumstats.csv, title("year `y' sample line weight")  main(mean) aux(sd) nostar unstack nonote label append
		
		
		if `y'>=1970 {
		eststo: estpost tabstat schooling evermarr  schooling_sp inctot_sp ftotinc if $birth & year==`y' & $goiter<.  [weight=perwt], statistics(mean sd) columns(statistics)
		esttab est3 using sumstats.csv, title("person weight")  main(mean) aux(sd) nostar unstack nonote label append
			/*can use perwt for schooling b/c only for 78 here*/
		eststo: estpost tabstat agemarr   if $birth & year==`y' & $goiter<.  [weight=weightagemarr], statistics(mean sd) columns(statistics)
		esttab est4 using sumstats.csv, title("person weight")  main(mean) aux(sd) nostar unstack nonote label append
			/*because of the divide by 2*/			
		}
		estimates clear
	}		

*Main Results
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab using "tables_main",  title("Main Table")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 

*Pre-Trends Table
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter} c.during#c.$goiter c.pre#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & inrange(birthyr,1916,1931), cluster(bpl) 
		estadd ysumm	
	}
	
	esttab using "tables_main",  title("Pre-Trends Table")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 

*Year-By-Year 
	*year by year tables
	cap g birthyrz=birthyr
	replace birthyrz=192300 if birthyr==1923

				
	foreach var in  employed labforce  worked_40   ihsinctot  {	
		eststo a`var': reg `var' i.birthyrz#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & inrange(birthyr,1914,1931), cluster(bpl) 
		estadd ysumm	
		
		parmest, saving("yby_`var'", replace ) level(90 95)
	}
		esttab a* using "tables_online",  title("Event Study")  append  ///
		csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs") star(* 0.10 ** 0.05 *** 0.01)
		estimates clear 
		
		eststo aihsinctot2: reg ihsinctot i.birthyrz#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weightihsinctot] ///
		if inrange(year,1950,1980) & inrange(birthyr,1912,1931), cluster(bpl) 
		estadd ysumm	
		
		parmest, saving("yby_ihsinctot1912", replace ) level(90 95)		
		

*By Gender
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab f* using "tables_main",  title("Females")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_main",  title("Males")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	
	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar}  ///
			c.after#c.${goiter} c.during#c.$goiter  	$byvar  $byvarcontrols [weight=weight`var'] ///			
		if inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	esttab using "tables_main",  title("By Gender Fully Interacted")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar)  scalars("ymean Mean" "N Obs" "controls controls") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 

*By Gender and Census 
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo fe`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1960) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo me`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1960) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
		
		eststo fl`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1970,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo ml`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1970,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab fe* using "tables_main",  title("Females Early Censuses")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	 
	esttab fl* using "tables_main",  title("Females Late Censuses")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab me* using "tables_main",  title("Males Early Censuses")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab ml* using "tables_main",  title("Males Late Censuses")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	estimates clear

*Robustness Table	
	global robust c.comyrs c.mobrate c.after#c.unemp1930 c.during#c.unemp1930 c.after#c.infkofscale c.during#c.infkofscale c.after#c.malmort1890scale c.during#c.malmort1890scale c.after#c.dblack c.during#c.dblack c.after#c.popgrowth c.during#c.popgrowth
	
		foreach var in employed labforce  worked_40   ihsinctot  {
		
			eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls $robust ///
			[weight=weight`var'] ///
			if inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
			estadd ysumm
			
			eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls $robust ///
			[weight=weight`var'] ///
			if inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
			estadd ysumm
			
		}
			local keeplist: subinstr global robust "c.comyrs" "comyrs"
			local keeplist: subinstr local keeplist "c.mobrate" "mobrate"
	
			esttab f* using "tables_main",  title("Females: Additional Controls ")  append  ///
			csv se(a3) keep(c.after#c.${goiter} c.during#c.$goiter `keeplist')  scalars("ymean Mean" "N Obs") star(* 0.10 ** 0.05 *** 0.01)
			
			esttab m* using "tables_main",  title("Males: Additional Controls")  append  ///
			csv se(a3) keep(c.after#c.${goiter} c.during#c.$goiter `keeplist')  scalars("ymean Mean" "N Obs") star(* 0.10 ** 0.05 *** 0.01)
			estimates clear	
			
	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls $robust
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar} ///
			c.after#c.${goiter} c.during#c.$goiter  	$byvar  $byvarcontrols [weight=weight`var'] ///			
		if inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	esttab using "tables_main",  title("By Gender Fully Interacted")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar)  scalars("ymean Mean" "N Obs" "controls controls") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear
	
*Education/Marital Outcomes
	foreach var in schooling evermarr agemarr schooling_sp ihsinctot_sp ihsftotinc {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1970,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1970,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}

	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in  schooling evermarr agemarr schooling_sp ihsinctot_sp ihsftotinc  {	
		eststo z`var': reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar} c.after#c.${goiter} c.during#c.$goiter  $byvar  $byvarcontrols [weight=weight`var'] ///			
		if inrange(year,1970,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	preserve
		keep if $birth & inrange(year,1970,1980)
		keep *agemarr* pernum year serial datanum year bpl $goiter $region year latitude during after pre female* black* birthyr
		expand 32
		bys year datanum serial pernum: g age=13 +_n /*should go from 14 to 45, 1/99 pctiles */
		sum age
		g married=1 if agemarr<=age
		replace married=0 if agemarr>age & agemarr<.
		replace married=0 if agemarruncond<. & agemarr==.

				

		eststo f: reg married c.after#c.${goiter} c.during#c.$goiter age i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weightagemarr] ///
		if inrange(year,1970,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m: reg married c.after#c.${goiter} c.during#c.$goiter age i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weightagemarr] ///
		if inrange(year,1970,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	

		global byvar female
		global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
		global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
		display "$byvarcontrols"	
		
		eststo z: reg married c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar}  ///
			c.after#c.${goiter} c.during#c.$goiter age c.age#c.${byvar} $byvar  $byvarcontrols [weight=weightagemarr]  ///			
		if inrange(year,1970,1980) & ${birth}, cluster(bpl) 					
	restore

	
	esttab f* using "tables_main",  title("Females: Education/Marital Outcomes")  append  ///
	csv se(a3) keep(*#c.$goiter age)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_main",  title("Males: Education/Marital Outcomes")  append  ///
	csv se(a3) keep(*#c.$goiter age)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab z* using "tables_main",  title("By Gender Fully Interacted: Education/Marital Outcomes")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar age)  scalars("ymean Mean" "N Obs") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	

	

*Other Income Variables (By Gender)
	foreach var in inctot3 inctot2  lninctot_cond2 {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab f* using "tables_main",  title("Other Income Variables: Females")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_main",  title("Other Income Variables: Males")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	
	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in inctot3 inctot2  lninctot_cond2  {	
		eststo: reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar}  ///
			c.after#c.${goiter} c.during#c.$goiter  	$byvar  $byvarcontrols [weight=weight`var'] ///			
		if inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	esttab using "tables_main",  title("Other Income Variables: By Gender Fully Interacted")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar)  scalars("ymean Mean" "N Obs" "controls controls") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear

*Online Appendix

	*Mean Reversion		
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls ///
		c.after#c.base`var'female c.during#c.base`var'female [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls ///
		c.after#c.base`var'male c.during#c.base`var'male [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab f* using "tables_online",  title("Mean Reversion: Females")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_online",  title("Mean Reversion: Males")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	
	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar} ///
			c.after#c.${goiter} c.during#c.$goiter $byvar  ///
			c.after#c.base`var'gender c.during#c.base`var'gender ///
			c.after#c.base`var'gender#c.${byvar} c.during#c.base`var'gender#c.${byvar} ///
			$byvarcontrols [weight=weight`var'] ///			
		if inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	esttab using "tables_online",  title("Mean Reversion: By Gender Fully Interacted")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar)  scalars("ymean Mean" "N Obs" "controls controls") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 	

*Exclude Dust Bowl, South, Restrict Age 27-36 only
foreach restrict in No_DustBowl No_South Aged27_36 {
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if ${restrict_`restrict'} & inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls [weight=weight`var'] ///
		if ${restrict_`restrict'} & inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab f* using "tables_online",  title("`restrict': Females")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_online",  title("`restrict': Males")  append  ///
	csv se(a3) keep(*#c.$goiter)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	
	*Fully Interacted Model
	global byvar female
	global byvarcontrols i.bpl i.birthyr i.birthyr#i.$region $controls
	global byvarcontrols=subinstr("$byvarcontrols ", " ", "#i.$byvar ",.)
	display "$byvarcontrols"	
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo: reg `var' c.after#c.${goiter}#c.${byvar} c.during#c.$goiter#c.${byvar}  ///
			c.after#c.${goiter} c.during#c.$goiter  	$byvar  $byvarcontrols [weight=weight`var'] ///			
		if ${restrict_`restrict'} & inrange(year,1950,1980) & ${birth}, cluster(bpl) 
		estadd ysumm	
	}

	esttab using "tables_online",  title("`restrict': By Gender Fully Interacted")  append  ///
	csv se(a3) keep(c.after#c.${goiter}* c.during#c.$goiter* $byvar)  scalars("ymean Mean" "N Obs" "controls controls") star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 		
}	

*Control State of Residence Goiter
	foreach var in employed labforce  worked_40   ihsinctot  {	
		eststo f`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls ///
		c.after#c.${goiter}res c.during#c.${goiter}res i.statefip [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==1, cluster(bpl) 
		estadd ysumm	
		
		eststo m`var': reg `var' c.after#c.${goiter} c.during#c.$goiter i.bpl i.birthyr i.birthyr#i.$region $controls ///
		c.after#c.${goiter}res c.during#c.${goiter}res i.statefip [weight=weight`var'] ///
		if inrange(year,1950,1980) & ${birth} & female==0, cluster(bpl) 
		estadd ysumm	
	}
	
	esttab f* using "tables_online",  title("Control for State of Residence Goiter: Females")  append  ///
	csv se(a3) keep(*#c.$goiter *#c.${goiter}res)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	
	esttab m* using "tables_online",  title("Control for State of Residence Goiter: Males")  append  ///
	csv se(a3) keep(*#c.$goiter *#c.${goiter}res)  scalars("ymean Mean" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)
	estimates clear 
	
*Cohort Composition
	collapse (count) N=male (sum) Nm=male (mean) male [fweight=perwt] if year==1940, by(birthyr latitude bpl bplregion9 goiterldscale after during year *1920bpl) 
	g Nf=N - Nm
	g lnN=ln(N)
	g lnNf=ln(Nf)
	g lnNm=ln(Nm)
	sort bpl birthyr

	foreach var in N  male    {
	eststo: reg `var' c.${goiter}#c.after c.${goiter}#c.during i.bpl i.birthyr c.during#c.female1920bpl c.during#c.black1920bpl  c.after#c.female1920bpl c.after#c.black1920bpl c.latitude#c.after c.latitude#c.during if birthyr>=1920 & birthyr<=1931 , cluster(bpl)
		estadd ysumm
	}	
	
	esttab using "tables_online", title("Cohort Composition")  append  ///
	csv se(a3) keep(c.${goiter}#c.after c.${goiter}#c.during)  ///
	scalars("ymean Mean" "ysd sd" "N Obs" ) star(* 0.10 ** 0.05 *** 0.01)

